package com.kt.app.ui.components


import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AddCircleOutline
import androidx.compose.material.icons.filled.Home
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties

@Composable
fun DropdownMenusSample() {
    val context = LocalContext.current
    var expanded by remember { mutableStateOf(false) }
    Row {
        Icon(
            Icons.Default.AddCircleOutline,
            contentDescription = null,
            modifier = Modifier
                .size(50.dp)
                .clickable {
                    expanded = !expanded
                })



        DropdownMenu(
            expanded = expanded, onDismissRequest = {
                expanded = false
            }, properties = PopupProperties(
                focusable = true,
                dismissOnBackPress = true,
                excludeFromSystemGesture = true
            )
        ) {
            DropdownMenuItem(text = { Text("菜单1") }, onClick = {
                Toast.makeText(context, "菜单1", Toast.LENGTH_SHORT).show()
                expanded = false
            })
            DropdownMenuItem(text = { Text("菜单2") }, onClick = {
                Toast.makeText(context, "菜单2", Toast.LENGTH_SHORT).show()
                expanded = false
            })
            DropdownMenuItem(text = { Text("菜单3") }, onClick = {
                Toast.makeText(context, "菜单3", Toast.LENGTH_SHORT).show()
                expanded = false
            })
        }
        Icon(
            Icons.Default.Home,
            contentDescription = null,
            modifier = Modifier
                .size(50.dp)
                .clickable {
//            expanded  = !expanded
                })

    }
}

@Preview
@Composable
fun DropdownMenusSamplePreview() {
    DropdownMenusSample()
}

